from django.db import models

# Create your models here.
class UserEntity(models.Model):
    name=models.CharField(max_length=20,verbose_name="名称",unique=True)
    age=models.IntegerField(default=0,verbose_name="年龄")
    phone=models.CharField(max_length=11,verbose_name="手机号")

    class Meta:
        #制定当前模型映射成哪一个表
        db_table='app_user'
        verbose_name='用户'
        verbose_name_plural=verbose_name

class CateTypeEntity(models.Model):
    name=models.CharField(max_length=20,verbose_name="分类名称",unique=True)
    order_num=models.IntegerField(verbose_name="排序")

    class Meta:
        #制定当前模型映射成哪一个表
        db_table='t_category'
        ordering=['-order_num']
        verbose_name='水果类别'
        verbose_name_plural=verbose_name

class FruitEntity(models.Model):
    name=models.CharField(max_length=20,verbose_name="水果名")
    price=models.FloatField(verbose_name='价格')
    category=models.ForeignKey(CateTypeEntity,on_delete=models.CASCADE)
    source=models.CharField(max_length=30,verbose_name="原产地")

    def __str__(self):
        return self.name+"-"+self.source
    class Meta:
        db_table='t_fruit'
        # ordering = ['-order_num']
        verbose_name = '水果'
        verbose_name_plural = verbose_name

